//
//  SortsOfGiftViewController.m
//  FlyGift
//
//  Created by lanou3g on 15/7/11.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "SortsOfGiftViewController.h"
#import "AllTopicTableViewController.h"
#import "ClassesViewController.h"
#import "CategoryListViewController.h"
#define KScrollViewJumpUrl @"http://api.liwushuo.com/v1/collections/%@/posts?gender=1&generation=1&limit=20&offset=0"
#define KChannelURL @"http://api.liwushuo.com/v1/channels/%@/items?limit=20&offset=0" //礼物


@interface SortsOfGiftViewController ()
@property(nonatomic, assign)NSInteger index;
@property(nonatomic, strong)GuideViewController *guideViewVC;
@property(nonatomic, strong)GiftViewController *giftViewVC;
@end

@implementation SortsOfGiftViewController
- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    [self loadSegment];
    /**
     添加视图控制器
     */
    self.guideViewVC = [[GuideViewController alloc]init];
    [self.view addSubview:self.guideViewVC.view];
    self.giftViewVC = [[GiftViewController alloc] init];
    
    __block SortsOfGiftViewController *BlockSelf = self;
    self.guideViewVC.bannerView.moreButtonBlock = ^(UIButton *button){
        [BlockSelf moreAction:button];
    };
    
    self.guideViewVC.bannerView.clickItemBlock = ^(NSString *bannerId){
        [BlockSelf clickBannerItemWithID:bannerId];
    };
    
    self.guideViewVC.clickChannelItemBlock = ^(NSString *channelId)
    {
        [BlockSelf  clickChannelItemWithID:channelId];
    };
    
    self.giftViewVC.clickSubcategoriesItemBlock = ^(NSString *subcategorieId,NSString *name)
    {
        [BlockSelf clickSubcategoriesItemWithID:subcategorieId name:name];
    };

}

#pragma mark - 点击事件部分

- (void)moreAction:(UIButton *)button
{
    AllTopicTableViewController *allTopicVc = [[AllTopicTableViewController alloc] init];
    [self.navigationController pushViewController:allTopicVc animated:YES];
}

#pragma mark - 点击轮播海报跳转
- (void)clickBannerItemWithID:(NSString *)ID
{
    NSString *url = [NSString stringWithFormat:KScrollViewJumpUrl,ID];
    ClassesViewController *classViewVC = [[ClassesViewController alloc]init];
    [classViewVC classScrollViewRequestWithUrl:url];
    [self.navigationController pushViewController:classViewVC animated:YES];
}

- (void)clickChannelItemWithID:(NSString *)ID
{
    NSString *url = [NSString stringWithFormat:KChannelURL,ID];
    ClassesViewController *classViewVC = [[ClassesViewController alloc]init];
    [classViewVC classTableViewRequestWithUrl:url];
    [self.navigationController pushViewController:classViewVC animated:YES];
}

- (void)clickSubcategoriesItemWithID:(NSString *)ID name:(NSString *)name
{
    CategoryListViewController *categoryListVC = [[CategoryListViewController alloc]init];
    categoryListVC.titleName = name;
    [categoryListVC categoryListDataRequestWithID:ID];
    [self.navigationController pushViewController:categoryListVC animated:YES];
}

#pragma mark - 添加分段控件
- (void)loadSegment
{
    UISegmentedControl *titleSegmentControl = [[UISegmentedControl alloc]initWithItems:@[@"攻略",@"礼物"]];
    self.navigationItem.titleView = titleSegmentControl;
    [titleSegmentControl setWidth:100 forSegmentAtIndex:0];
    [titleSegmentControl setWidth:100 forSegmentAtIndex:1];
    titleSegmentControl.tintColor = [UIColor whiteColor];
    [titleSegmentControl addTarget:self action:@selector(titleSegmentAction:) forControlEvents:UIControlEventValueChanged];
    // 开始进入页面 显示攻略页面
    titleSegmentControl.selectedSegmentIndex = 0;
}

#pragma mark - 点击segment切换页面
- (void)titleSegmentAction:(UISegmentedControl *)segment
{
    self.index = segment.selectedSegmentIndex;
    if (segment.selectedSegmentIndex == 0)
    {
        [self.view addSubview:self.guideViewVC.view];
        [self.giftViewVC.view removeFromSuperview];
    }
    else
    {
        [self.view addSubview:self.giftViewVC.view];
        [self.guideViewVC.view removeFromSuperview];
    }
}

@end
